#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QToolButton>
#include <QStandardItemModel>
#include <QRubberBand>
#include "CommConfig/commconfig.h"
#include "Tree/treeitem.h"
#include "Tree/treemodel.h"

namespace Ui {
class MainWindow;
}

// OPTION
typedef struct _OPTION{
    int layerID;
    QColor color;
    QString formula;
    QString tag;
    _OPTION()
    {
        formula = "";
    }
}OPTION;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void leftMainClick();
    void on_pushButtonSettingSave_released();

    void newMessageArrived(MESSAGE mMsg);

    void slotTreeMenu(const QPoint &pos);
    void slotTreeMenuAddToPlot(bool checked);
    void slotTreeMenuChangeColor(bool checked);
    void slotTreeMenuEditExpression(bool checked);

    void on_pushButtonPlot_released();
    void on_pushButtonReset_released();

    void on_cbox_axis_x_pointes_currentIndexChanged(const QString &arg1);

    //鼠标事件
    void mousePress(QMouseEvent* mevent);
    void mouseMove(QMouseEvent *mevent);
    void mouseRelease(QMouseEvent *mevent);

private:

    void initTreeView();
    void loadConfigFile();
    void initLeftMain();
    void initPlotGraphView();

    void notifyActions();

    // function
    void insertNodeMsg(MESSAGE &msg);
    void replotGraph(MESSAGE &msg);
    // MainUI
    Ui::MainWindow *ui;

    // Plot
    bool        plotting;
    int         PLOT_NUMBER_OF_POINTS;                                                    // Number of points plotted
    float_t     PLOT_LINE_PEN_WIDTH;                                                      // Line width
    int         PLOT_LEGEND_BRIGHTLESS;                                                   // Legend brightless
    qint64      dataPointNumber;
    QRubberBand *rubberBand;
    QPoint      rubberOrigin;

    // Status plotting variable
    //CommCinfug
    CommConfig  *mCommConfig;

    //TreeModel
    TreeModel* mModel;                                                                // Timer used for replotting the plot
    QVector<TreeItem*> parents;
    QQueue<MESSAGE> mMavMsg;
    QMap<QString,MESSAGE> mMsgMap;
    QMap<QString,OPTION> mOptionMap;

    //Leftview
    QList<int> pixCharMain;
    QList<QToolButton *> btnsMain;

    QString mThemeStyle;
};

#endif // MAINWINDOW_H
